<?php

namespace app\core\services\user;

use app\core\repositories\user\UserRepository;
use app\core\forms\user\ProfileEditForm;
use yii\base\Exception;

class ProfileService
{
    private UserRepository $users;

    public function __construct(UserRepository $users)
    {
        $this->users = $users;
    }

    public function editAvatar($id, $user_pic): void
    {
        $user = $this->users->get($id);
        $user->editAvatar($user_pic);
        $this->users->save($user);
    }

    /**
     * @throws Exception
     */
    public function edit($id, ProfileEditForm $form): void
    {
        $user = $this->users->get($id);
        $user->editProfile($form->username, $form->password);
        $this->users->save($user);
    }
}
